<template>
  <page-main>
    <div class="list">
      <el-table :data="share_list_data" height="600" stripe fit v-loading="loading">
        <el-table-column prop="key" label="key">
          <template slot-scope="scope">
              <el-link type="primary" :href="share_Get_Url(scope.row.key)" >{{Share_Key_Handler(scope.row.key)}}</el-link>
           </template>
        </el-table-column>
        <el-table-column prop="pwd" label="是否公开">
          <template slot-scope="scope">
            <span v-if="scope.row.pwd == 0">
              <i class="el-icon-check"></i>
            </span>
            <span v-else>
              <i class="el-icon-close"></i>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="pwd" label="秘钥">
          <template slot-scope="scope">{{scope.row.pwd == 0 ? '-' : scope.row.pwd}}</template>
        </el-table-column>
        <el-table-column prop="shareDate" label="分享时间">
          <template slot-scope="scope">{{FileUtils.timestampToTime(scope.row.shareDate)}}</template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
                <el-button @click="share_Remove(scope.row.key)" type="primary" size="small">取消分享</el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </page-main>
</template>
<script>
import { getShareMeList, removeShare } from '@/api/requests/share'
import {success} from '@/util/message'
import FileUtils from '@/util/file'
export default {
  data () {
    return {
      FileUtils,
      loading: false,
      share_list_data: [],
      share_url:'',
    }
  },
  created () {
    this.Share_Get_List()
  },
  methods: {
    Share_Get_List () {
      this.loading = true
      getShareMeList().then(res => {
        setTimeout(() => {
          this.share_list_data = JSON.parse(res.data)
          this.loading =false
        }, 1000);
      })
    },
    share_Get_Url (key) {
      let k = this.Share_Key_Handler(key)
      return  '/#/share/' + k
    },
    share_Remove (key) {
      let k = this.Share_Key_Handler(key)
      removeShare(k).then(res => {
        if(res.code == 200){
success(this,'删除成功')
  this.Share_Get_List()
        }
      })

    },
    Share_Key_Handler (key) {
      let temp = key.substring(6)
      if (temp.indexOf(':') != -1) {
        temp = temp.substring(0, temp.indexOf(':'))
      }
      return temp
    }
  },
}
</script>